home *** CD-ROM | disk | FTP | other *** search
- Path: news.kth.se!news
- From: Andreas SwΣrdh <da1-asw@nada.kth.se>
- Newsgroups: comp.lang.c++
- Subject: template with unknown classes!
- Date: Wed, 13 Mar 1996 17:29:04 +0100
- Message-ID: <3146F7D0.791D@nada.kth.se>
- NNTP-Posting-Host: sl14.modempool.kth.se
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (Win95; I)
-
- My real problem is that I havn't found any good referens about
- advance templates.
-
- So my question is: If you got an exemple like the one below
- is there an solution to find?
-
- class listhandler
- {
- private:
- node *head; // my baseclass pointer. could be a Void* too, just
- public: // to make it even more complicated.
- listhandler(){head = null;};
- void new_object(); // here is the functions definition.
- ...
- ...
- }
- // I Would like to create an listhandler that works on everything. That
- can
- // take an unknown class (of course it must be a defined class) and
- create it
- // with NEW. I thought it would be easy to do with templates but haven't
- had
- // any success yet. The problem is that I don't want the hole class to
- be a
- // template, just THIS funktion. Is there a solution with templetes or
- do
- // you have to use friend in some sort of way? Maybe use of
- dummy-class-pointer
- // just to get the right class type?! Would be most greatful for fast
- replies.
-
- // The possible function?!
-
- template<class object>void new_object() // or something like that!
- {
- if(!head)
- head = new object; // where object doesn't have to be known.
- ... // And the constuctor of object initializes it!
- ...
- }
-
- // It shall be intresting to see what kind of solutions you can dig out
- // of your closet!
- //
- // If you wanna mail me personaly: MAILTO:da1_asw@nada.kth.se
- //
- // Bye for know!!
-